package guinong.com.gnw.ui.widged;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import guinong.com.gnw.R;
import guinong.com.gnw.utils.CommonUtils;

/**
 * 等待框
 */
public class CustomProgressDialog {
    public static Dialog createDialog(Context context, String msg) {
        final Dialog dialog = new Dialog(context, R.style.DialogStyle);
        dialog.setCancelable(true);
        View view = LayoutInflater.from(context).inflate(R.layout.view_progress_dialog, null);
        dialog.setContentView(view);
        ((TextView) view.findViewById(R.id.loading_msg)).setText(msg);
        Window mWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {//横屏
            lp.width = CommonUtils.getDisplayHeight(context) / 10 * 8;
        } else {
            lp.width = CommonUtils.getDisplayWidth(context) / 10 * 8;
        }
        mWindow.setAttributes(lp);
        dialog.show();
        return dialog;
    }
}
